package com.system.service.impl;

import com.system.mapper.DocumentMapper;
import com.system.po.Document;
import com.system.po.PagingVO;
import com.system.service.DocumentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class DocumentServiceImpl implements DocumentService {

    @Resource
    private DocumentMapper documentMapper;

    @Override
    public List<Document> findAll(Integer toPageNo) throws Exception{
        PagingVO pagingVO=new PagingVO();
        pagingVO.setToPageNo(toPageNo);
        return documentMapper.selectAll(pagingVO);
    }

    @Override
    public List<Document> findByTitle(String title) throws Exception{
        return documentMapper.selectByTitle(title);
    }

    @Override
    public Document findById(Integer documentID) throws Exception {
        return documentMapper.selectById(documentID);
    }

    @Override
    public int getCountCouse() {
        return documentMapper.getCount();
    }

    @Override
    public void save(Document document) throws Exception {
        documentMapper.insertDocument(document);
    }

    @Override
    public void updateTagById(Integer documentid) throws Exception {
        Document document=new Document();
        document.setTag(1);
        document.setDocumentid(documentid);
        documentMapper.updateTagById(document);
    }

    @Override
    public void updateById(Document document) throws Exception {
        documentMapper.updateById(document);
    }

    @Override
    public void deleteById(Integer documentid) throws Exception {
        documentMapper.deleteById(documentid);
    }

}
